#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/4/15 15:47
# @Author  : Chenmm
# @File    : SysLog.py
# @Software: PyCharm

from app import db
from datetime import datetime


class SysLog(db.Model):
    __tablename__ = 'sys_log'

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True, comment='主键')
    module = db.Column(db.String(50), nullable=False, comment='日志模块')
    request_method = db.Column(db.String(64), nullable=False, comment='请求方式')
    request_params = db.Column(db.Text, comment='请求参数')
    response_content = db.Column(db.Text, comment='返回参数')
    content = db.Column(db.String(255), nullable=False, comment='日志内容')
    request_uri = db.Column(db.String(255), comment='请求路径')
    method = db.Column(db.String(255), comment='方法名')
    ip = db.Column(db.String(45), comment='IP地址')
    province = db.Column(db.String(100), comment='省份')
    city = db.Column(db.String(100), comment='城市')
    execution_time = db.Column(db.BigInteger, comment='执行时间(ms)')
    browser = db.Column(db.String(100), comment='浏览器')
    browser_version = db.Column(db.String(100), comment='浏览器版本')
    os = db.Column(db.String(100), comment='终端系统')
    create_by = db.Column(db.BigInteger, comment='创建人ID')
    create_time = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
    is_deleted = db.Column(db.SmallInteger, default=0, comment='逻辑删除标识(1-已删除 0-未删除)')

    __table_args__ = (
        db.Index('idx_create_time', 'create_time'),
        {'comment': '系统日志表', 'mysql_engine': 'MyISAM'}
    )
